/**
 * 枚举工具
 */
export class EnumUtil {

    /**
     * 遍历数字枚举类型
     * @param numEnum 数字枚举
     * @param each 遍历回调 有返回值会打断遍历
     */
    static eachNumEnum(numEnum: any, each: (val: number, key: string) => any) {
        for (const key in numEnum) {
            if (isNaN(Number(key))) {
                if (each(numEnum[key], key)) {
                    return;
                }
            }
        }
    }

    /**
     * 将数字枚举类型转为[key,val]数组
     * @param numEnum 
     */
    static getNumEnumItems(numEnum: any) {
        const items: [string, number][] = [];
        this.eachNumEnum(numEnum, (val, key) => {
            items.push([key, val]);
        });
        return items;
    }
}